$(() => {
    //出生日期使用下拉选择组件
    layui.use(() => {
        let laydate = layui.laydate;
        laydate.render({
            elem: "#birthday"
        });
    });

    //提交按钮事件
    $("#submit-btn").click(() => {
        save(function (success) {
            if (success) {
                layui.use(() => {
                    let layer = layui.layer;
                    layer.msg("新增电影成功");
                });
            }
        });
    });
});

//保存学生，cb回调函数
function save(cb) {
    // let newid = $("#stuId").val();
    let author = $("#name").val();
    let category = $(":input[name=sex]:checked").val();
    let time = $("#birthday").val();
    let title = $("#phone").val();
    let actor = $("#actor").val();
    let $aiEditor = $("#aiEditor");
    let content=$aiEditor.html();

    // 找到起始和结束字符串在原始字符串中的索引
    let startIndex = content.indexOf("</aie-header>");
    let endIndex = content.indexOf("<aie-footer>");


    // 使用 substring 方法截取中间内容
    content=content.substring(startIndex + "</aie-header>".length, endIndex);




    let url = "/api/v1/news"
    $.ajax({
        url,
        method: "post",
        dataType: "json",
        data: {
            // newid,
            title,
            category,
            author,
            time,
            content,
            actor
        },
        success(resp) {
            if (typeof cb === "function") {
                cb(resp.success);
            }
        }
    });
}